package com.baihui.taobao.transition;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baihui.taobao.authorize.TaoBaoSessionInfo;
import com.taobao.api.ApiException;
import com.taobao.api.domain.Sku;
import com.taobao.api.request.ItemSkuGetRequest;
import com.taobao.api.request.ItemSkusGetRequest;
import com.taobao.api.response.ItemSkuGetResponse;
import com.taobao.api.response.ItemSkusGetResponse;

/**
 * Created by Kevin. User: HSZM1106-0312 Date: 12-1-27 Time: 下午9:39
 */
public class SKUCase extends Cases {
	public SKUCase(TaoBaoSessionInfo info) {
		super(info);
	}

	public Sku getSkuByNumIds(Long numId) throws Exception {
		ItemSkuGetRequest req = new ItemSkuGetRequest();
		req.setFields(parseFields(Sku.class));
		req.setNumIid(numId);
		try {
			ItemSkuGetResponse response = getTaoBaoClient().execute(req);
			Map<Long, Sku> map = new HashMap<Long, Sku>();
			Sku sku = response.getSku();

			return sku;
		} catch (ApiException e) {
			throw new Exception(e);
		}
	}

	public List<Sku> getSkuByNumIds(String numIds) throws Exception {
		ItemSkusGetRequest req = new ItemSkusGetRequest();
		req.setFields(parseFields(Sku.class));
		req.setNumIids(numIds);
		try {
			ItemSkusGetResponse response = getTaoBaoClient().execute(req);
			Map<Long, Sku> map = new HashMap<Long, Sku>();
			List<Sku> sku = response.getSkus();

			return sku;
		} catch (ApiException e) {
			throw new Exception(e);
		}
	}

	private String getNumIdStr(List<Long> numId) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; numId != null && i < numId.size(); i++) {
			if (i < numId.size() - 1) {
				sb.append(numId.get(i).toString()).append(",");
			} else {
				sb.append(numId.get(i).toString());
			}
		}
		return sb.toString();
	}

}
